<?php

/**
 * valid key checking
 *
 * @param  String  key for checking
 * @return Integer 0 = not valid
 *                 1 = valid but not in database
 *                 2 = valid and in database
 */


/**
 * LanguageID
 */
function isValidLanguageID($languageID) {
    global $MySQL_DB;

    // languageID only uses A-z and 0-9
    if(preg_match('/[^a-z0-9]/i',$languageID)) {
        return 0;
    }

    // check if languageID is valid
    $res_check_lang = execute_query("SELECT ID FROM %PRE%language WHERE ID = '".$languageID."'",$MySQL_DB);
    if($check_lang = $res_check_lang->fetch_object()) {
        return 2;
    }
    else {
        return 1;
    }
}

/**
 * UserID
 */
function isValidUserID($userID) {
    global $MySQL_DB;

    // userID must be an integer
    if(!is_int($userID)) {
        return 0;
    }

    // check if userID is in database
    $res_check_user = execute_query("SELECT ID FROM %PRE%user WHERE ID = ".$userID,$MySQL_DB);
    if($check_user = $res_check_user->fetch_object()) {
        return 2;
    }
    else {
        return 1;
    }
}

?>